package com.geovis.emergency.spd.controller.command;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.geovis.common.core.api.Result;
import com.geovis.common.core.controller.BaseController;
import com.geovis.emergency.spd.biz.command.mapper.TfljMapper;
import com.geovis.emergency.spd.biz.command.service.IOdsZgtfwTyphoonService;
import com.geovis.emergency.spd.biz.command.service.TfService;
import com.geovis.emergency.spd.biz.pc.service.IPcSchedulingEventService;
import com.geovis.emergency.spd.entity.command.entity.Tflj;
import com.geovis.emergency.spd.entity.command.pojo.dto.SchedulingEventDTO;
import com.geovis.emergency.spd.entity.command.pojo.vo.OdsTyphoonVO;
import com.geovis.emergency.spd.entity.pc.pojo.vo.PcSchedulingEventVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 指挥调度大屏-事件接口
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/10/25
 */
@RestController
@RequestMapping("/command/scheduling/event")
@RequiredArgsConstructor
@Api(value = "指挥调度大屏-事件接口", tags = "指挥调度大屏-事件接口")
@Slf4j
@Validated
@ApiSort(0)
public class CommandSchedulingEventController extends BaseController<IPcSchedulingEventService>{

    private final IOdsZgtfwTyphoonService typhoonService;

    private final TfService tfService;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType="header",name="appId",dataType="String",required=true,value="授权id"),
            @ApiImplicitParam(paramType="header",name="timestamp",dataType="String",required=true,value="当前时间戳(秒)"),
            @ApiImplicitParam(paramType="header",name="sign",dataType="String",required=true,value="签名")
    })
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "推送事件", notes = "推送事件接口，签名生成方法：md5(appId+appSecret+timestamp)")
    @PostMapping("/pushEvent")
    public Result<String> pushEvent(@Validated @RequestBody SchedulingEventDTO schedulingEventDTO) {

        String typhoonPointId=null;
        if(StringUtils.hasText(schedulingEventDTO.getTyphoonNo()))
        {
            typhoonPointId=tfService.getTyphoonLatestPointId(schedulingEventDTO.getTyphoonNo());
        }
        String id=baseService.pushEvent(schedulingEventDTO,typhoonPointId);
        if(id==null)
        {
            return Result.failed("创建演练失败!");
        }
        return Result.ok(id);
    }




    @ApiImplicitParams({
            @ApiImplicitParam(paramType="header",name="appId",dataType="String",required=true,value="授权id"),
            @ApiImplicitParam(paramType="header",name="timestamp",dataType="String",required=true,value="当前时间戳(秒)"),
            @ApiImplicitParam(paramType="header",name="sign",dataType="String",required=true,value="签名"),
            @ApiImplicitParam(paramType="path",name="mainEventId",dataType="String",required=true,value="演练主事件id")
    })
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "事件概况详情", notes = "事件概况详情，签名生成方法：md5(appId+appSecret+timestamp)")
    @GetMapping("/detailEvent/{drillId}")
    public Result<PcSchedulingEventVO> eventDetail(@PathVariable("drillId") String drillId) {
        PcSchedulingEventVO pcSchedulingEventVO = baseService.detailEvent(drillId);
//        if (ObjectUtil.isNotNull(pcSchedulingEventVO) && StrUtil.isNotBlank(pcSchedulingEventVO.getTyphoonNo())){
//            OdsTyphoonVO typhoon = typhoonService.getTyphoon(pcSchedulingEventVO.getTyphoonNo());
//            pcSchedulingEventVO.setTyphoon(typhoon);
//        }
        return Result.ok( pcSchedulingEventVO);
    }
}
